package com.cj.controller;

import com.cj.mapper.StudentMapper;
import com.cj.pojo.entity.Student;
import com.cj.pojo.until.Result;
import com.cj.pojo.vo.StudentVo;
import com.cj.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "学生操作APl")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping("list/{current}/{pageSize}")
    @ApiModelProperty(value = "根据条件分页查询学生信息")
    public Result list(
            @ApiParam(value = "当前页面",name ="current",required = true,defaultValue = "1")
            @PathVariable Integer current,
            @ApiParam(value = "每页条数",name ="pageSize",required = true,defaultValue = "10")
            @PathVariable Integer pageSize,
            @RequestBody StudentVo studentVo
            ){
        return studentService.findByPage(current,pageSize,studentVo);
    }
    @Autowired
    private StudentMapper studentMapper;
    @DeleteMapping("delete/{cid}")
    @ApiModelProperty("根据学生编号删除数据")
    public  Result delete(
            @ApiParam(name = "cid" ,value = "学生编号",required = true)
            @PathVariable Integer cid
    ){
        int i = studentMapper.deleteById(cid);
        return  new Result(200,"删除成功",i);
    }
@PutMapping("update")
    @ApiModelProperty("修改数据")
    public  Result update(
        @ApiParam(name = "cid" ,value = "学生编号",required = true)
          @RequestBody Student  student
){
    int ii = studentMapper.updateById(student);
    return new Result(200,"更新成功",ii);
}
@PutMapping("save")
    @ApiModelProperty("添加数据")

    public Result save(
        @ApiParam(name = "cid" ,value = "学生编号",required = true)
        @RequestBody Student  student
){

    int insert = studentMapper.insert(student);
    return new Result(200,"更新成功",insert);
}




}
